
#include <iostream>
#include <string>
#include <vector>
#include <boost/smart_ptr.hpp>
#include <boost/make_shared.hpp>

using namespace std;

class parent;
class child;

typedef boost::shared_ptr<parent> parent_ptr;
typedef boost::shared_ptr<child> child_ptr;

class parent
{
public:
    ~parent() {
        std::cout <<"父类析构函数被调用.\n";
    }
public:
    child_ptr children;
};

class child
{
public:
    ~child() {
        std::cout <<"子类析构函数被调用.\n";
    }
public:
    parent_ptr parent;
};

int main()
{
    parent_ptr father(new parent());
    child_ptr son(new child);
    // 父子互相引用。
    father->children = son;
    son->parent = father;


    std::cout<<"son use:"<<son.use_count() <<std::endl;
    std::cout<<"father use:"<<father.use_count() <<std::endl;
    return 0;
}



